/*****************************************************************
 MYD Engine v0.1

 file: tstgame.cpp
 created: 20/06/09
*****************************************************************/
#include "tstgame.h"

//-------------------------------------------------------------------
tstgame::tstgame(HINSTANCE hInstance)
:
Game(hInstance),
viewX(0),
viewY(0)
{
}
//-------------------------------------------------------------------------------------
tstgame::~tstgame(void)
{
}
//-------------------------------------------------------------------------------------

bool tstgame::onInit()
{
	this->initLight();

	//set up basic meshes
	my_mesh = new BasicObject(wn_renderer);
	my_mesh->setPos(5.0f, 0.0f, 0.0f);
	addEntity(my_mesh);

	//set up x files
	my_x_file = new Entity3d(wn_renderer);
	my_x_file->loadXFile("../../res/Xfiles/Airplane/", "airplane 2.x");
	my_x_file->setPos(-5.0f, 0.0f, 0.0f);
	my_x_file->setDim(0.5f, 0.5f, 0.5f);
	addEntity(my_x_file);

	Entity3d* my_x_file2;
	my_x_file2 = new Entity3d(wn_renderer);
	my_x_file2->loadXFile("../../res/Xfiles/", "spaceship 2.x");
	my_x_file2->setDim(0.5f, 0.5f, 0.5f);
	addEntity(my_x_file2);

	//Importer* pkImporter = getImporter();

	//cube->setPos(100,100,0);
	//cube->setDim(100,100);

	/*/add shape
	addEntity(m_pkShape);

	//set tilemap
	m_pkTilemap = pkImporter->createSpriteMap("../../res/mspacman-01.amf",-200,200);
	//m_pkTilemap->SetPos(0,0);
	//addEntity(m_pkTilemap);
	
	for(int i=0; i<m_pkTilemap->tilesVector.size();i++)
		addEntity(m_pkTilemap->tilesVector[i]);*/

	//set mesh
	//tstmesh.createTeapot(wn_renderer->D3Ddevice);
	//addEntity(&tstmesh);

	/*tstmesh3d.importXFile("../../res/blendercuby.x", wn_renderer->D3Ddevice);
	tstmesh3d.setPos(0,0,0);
	addEntity(&tstmesh3d);*/

	/*Vertexbuffer<TextureVertex, TEXTURE_VERTEX>* p = new Vertexbuffer<TextureVertex, TEXTURE_VERTEX>(36);

	Vertexbuffer<TextureVertex, TEXTURE_VERTEX>::Ptr wn_vb(p);

//TEST 1
	wn_vb->setVertex(0, TextureVertex(-1.0f, -1.0f, -1.0f) );
	wn_vb->setVertex(1, TextureVertex(-1.0f, 1.0f, -1.0f) );
	wn_vb->setVertex(2, TextureVertex(1.0f, 1.0f, -1.0f) );
	wn_vb->setVertex(3, TextureVertex(-1.0f, -1.0f, -1.0f) );
	wn_vb->setVertex(4, TextureVertex(1.0f, 1.0f, -1.0f) );
	wn_vb->setVertex(5, TextureVertex(1.0f, -1.0f, -1.0f) );
	wn_vb->setVertex(6, TextureVertex(-1.0f, -1.0f, 1.0f) );
	wn_vb->setVertex(7, TextureVertex(1.0f, 1.0f, 1.0f) );
	wn_vb->setVertex(8, TextureVertex(-1.0f, 1.0f, 1.0f) );
	wn_vb->setVertex(9, TextureVertex(-1.0f, -1.0f, 1.0f) );
	wn_vb->setVertex(10, TextureVertex(1.0f, -1.0f, 1.0f) );
	wn_vb->setVertex(11, TextureVertex(1.0f, 1.0f, 1.0f) );
	wn_vb->setVertex(12, TextureVertex(-1.0f, -1.0f, 1.0f) );
	wn_vb->setVertex(13, TextureVertex(-1.0f, 1.0f, 1.0f) );
	wn_vb->setVertex(14, TextureVertex(-1.0f, 1.0f, -1.0f) );
	wn_vb->setVertex(15, TextureVertex(-1.0f, -1.0f, 1.0f) );
	wn_vb->setVertex(16, TextureVertex(-1.0f, 1.0f, -1.0f) );
	wn_vb->setVertex(17, TextureVertex(-1.0f, -1.0f, -1.0f) );
	wn_vb->setVertex(18, TextureVertex(1.0f, -1.0f, -1.0f) );
	wn_vb->setVertex(19, TextureVertex(1.0f, 1.0f, -1.0f) );
	wn_vb->setVertex(20, TextureVertex(1.0f, 1.0f, 1.0f) );
	wn_vb->setVertex(21, TextureVertex(1.0f, -1.0f, -1.0f) );
	wn_vb->setVertex(22, TextureVertex(1.0f, 1.0f, 1.0f) );
	wn_vb->setVertex(23, TextureVertex(1.0f, -1.0f, 1.0f) );
	wn_vb->setVertex(24, TextureVertex(-1.0f, 1.0f, -1.0f) );
	wn_vb->setVertex(25, TextureVertex(-1.0f, 1.0f, 1.0f) );
	wn_vb->setVertex(26, TextureVertex(1.0f, 1.0f, 1.0f) );
	wn_vb->setVertex(27, TextureVertex(-1.0f, 1.0f, -1.0f) );
	wn_vb->setVertex(28, TextureVertex(1.0f, 1.0f, 1.0f) );
	wn_vb->setVertex(29, TextureVertex(1.0f, 1.0f, -1.0f) );
	wn_vb->setVertex(30, TextureVertex(-1.0f, -1.0f, 1.0f) );
	wn_vb->setVertex(31, TextureVertex(-1.0f, -1.0f, -1.0f) );
	wn_vb->setVertex(32, TextureVertex(1.0f, -1.0f, -1.0f) );
	wn_vb->setVertex(33, TextureVertex(-1.0f, -1.0f, 1.0f) );
	wn_vb->setVertex(34, TextureVertex(1.0f, -1.0f, -1.0f) );
	wn_vb->setVertex(35, TextureVertex(1.0f, -1.0f, 1.0f) );

	for(unsigned int i=0; i<36; i++)
	{
		TextureVertex& v = wn_vb->getVertex(i);
		v.NX = 1.0f;
		v.NY = 0.0f;
		v.NZ = 0.0f;
	}

	m.setVB(wn_vb);
	m.setDim(50, 50, 50);*/

	//--------------------

	/*Material mat;
	ZeroMemory(static_cast<void*>(&mat), sizeof(Material));
	mat.Ambient = D3DXCOLOR(4.0f, 0.0f, 0.0f, 255.0f);
	mat.Diffuse = D3DXCOLOR(0.0f, 255.0f, 0.0f, 255.0f);
	//mat.Emissive = D3DXCOLOR(255.0f, 0.0f, 0.0f, 255.0f);
	mat.Specular = D3DXCOLOR(255.0f, 255.0f, 255.0f, 255.0f);
	mat.Power = 10;
/*
	mat.Ambient = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
    mat.Diffuse = D3DXCOLOR(255.0f, 0.0f, 0.0f, 1.0f);
	mat.Specular = D3DXCOLOR(255.0f, 0.0f, 0.0f, 1.0f);
*/
	//m.wn_material = mat;

	/*Mesh m;
	m.setTexture(...);
	m.setVB(vb);
	*/

	return true;
}
//-------------------------------------------------------------------------------------
bool tstgame::onLoop()
{
	/** objects movement **/
	if(input->GetKeyDown(DIK_SPACE))
	{
		int curr_rotation_y = my_x_file->getRotationY();
		this->my_x_file->setRotation(0.0, curr_rotation_y += 5.0f, 0.0);
	}
	
	/** camera movement **/
	if(input->GetKeyDown(DIK_LEFT))
	{
		wn_camera.Strafe(-0.1f);
	}

	if(input->GetKeyDown(DIK_RIGHT))
	{
		wn_camera.Strafe(0.1f);
	}

	if(input->GetKeyDown(DIK_UP))
	{
		wn_camera.Fly(0.1f);
	}

	if(input->GetKeyDown(DIK_DOWN))
	{
		wn_camera.Fly(-0.1f);
	}

	if(input->GetKeyDown(DIK_NUMPADPLUS))
	{
		wn_camera.Walk(0.1f);
	}

	if(input->GetKeyDown(DIK_NUMPADMINUS))
	{
		wn_camera.Walk(-0.1f);
	}

	return false;
}
//-------------------------------------------------------------------------------------
bool tstgame::onDeinit()
{
	return true;
}